package o;

import android.content.Context;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import java.util.ArrayList;
import java.util.List;

public class boz implements bpm {
    private final Context ˊ;
    private final bpy ˏ;
    private String ॱ;

    public boz(@NonNull Context context, @NonNull bpy o_bpy) {
        this.ˊ = context;
        this.ˏ = o_bpy;
    }

    public void ˋ(boolean z) {
        if (z) {
            ˏ();
        } else {
            this.ˏ.ॱ(5, "Not signed the agreement.");
        }
    }

    public void ˊ(@NonNull String str) {
        boc.ˎ.ˊ("GetInstallStatesHandler", "getInstallStates, pkgName: " + str);
        this.ॱ = str;
        if (ccx.ॱ()) {
            ˏ();
            return;
        }
        boc.ˎ.ˏ("GetInstallStatesHandler", "Require to sign the agreement.");
        bpp.ˏ().ˏ(this);
        new bpq(this.ˊ, this.ॱ).ˎ();
    }

    private void ˏ() {
        if (TextUtils.isEmpty(this.ॱ)) {
            boc.ˎ.ˊ("GetInstallStatesHandler", "Run to unreachable logic.");
            return;
        }
        List<bol> ˎ = bor.ˎ().ˎ(this.ॱ);
        if (ˎ.isEmpty()) {
            this.ˏ.ॱ(7, "Not found the session, pkgName: " + this.ॱ);
            return;
        }
        ArrayList arrayList = new ArrayList();
        for (bol o_bol : ˎ) {
            if (o_bol.ʼ()) {
                bqd ˊ = ˊ(o_bol);
                if (ˊ != null) {
                    arrayList.add(ˊ);
                }
            }
        }
        if (arrayList.isEmpty()) {
            this.ˏ.ॱ(7, "Not found the download or install task, pkgName: " + this.ॱ);
        } else {
            this.ˏ.ˋ(arrayList);
        }
    }

    @Nullable
    static bqd ˊ(@NonNull bol o_bol) {
        SessionDownloadTask ॱ = bof.ˏ().ॱ(o_bol.ʽ());
        if (ॱ != null) {
            return boy.ॱ(o_bol, ॱ);
        }
        ManagerTask ˏ = bof.ˋ().ˏ(o_bol.ॱॱ());
        if (ˏ != null) {
            return bpe.ˋ(o_bol, ˏ, 0);
        }
        if (o_bol.ᐝ()) {
            return null;
        }
        return bpe.ॱ(o_bol);
    }
}
